package mylogger

import (
	"fmt"
	"path"
	"runtime"
	"strings"
)

type LogLevel uint8



type Logger interface {
	Debug(format string, a ...interface{})
	Info(format string, a ...interface{})
	Warning(format string, a ...interface{})
	Error(format string, a ...interface{})
	Fatal(format string, a ...interface{})
}

const (
	DEBUG LogLevel = iota
	INFO
	WARNING
	ERROR
	FATAL
)

func parseLogLevel(s string) LogLevel {
	s = strings.ToLower(s)
	switch s {
	case "debug":
		return DEBUG
	case "info":
		return INFO
	case "warning":
		return WARNING
	case "error":
		return ERROR
	case "fatal":
		return FATAL
	default:
		return DEBUG
	}
}

func levelToStr(level LogLevel) string {
	switch level {
	case DEBUG:
		return "DEBUG"
	case INFO:
		return "INFO"
	case WARNING:
		return "WARNING"
	case ERROR:
		return "ERROR"
	case FATAL:
		return "FATAL"
	default:
		return "DEBUG"
	}
}

func getInfo(n int)(funcName, fileName string,line int){
	pc,file,line,ok:=runtime.Caller(n)
	if !ok{
		fmt.Printf("runtime.Caller failed\n")
		return
	}
	funcName=runtime.FuncForPC(pc).Name()
	funcName=strings.Split(funcName,".")[1]
	fileName=path.Base(file)
	return funcName,fileName,line
}
